public class HomeWork04_02{
    public static void main(String[] args){
        int ans = 0;
        int flag = -1;
        for(int i = 1; i <= 1000; i++){
            ans += i;
            if(ans>500 && flag == -1){
                flag = i;
            }
        }
        System.out.println("1~1000的和：" + ans + 
                           "\n当加到" + flag + "时和大于500");
    }
}